$(function(){
	//单选框单击事件
	$("label").click(function(){
		var forId = $(this).attr("for");
		if(forId == null || forId.length == 0){
			return;
		}
		var radio = $("#"+forId);
		if(radio == null || !radio.hasClass("radio")){
			return;
		}
		radio.click();
	});
	$(".radio").click(function(){
		var name = $(this).attr('name');
		if(name == null || name.length == 0){
			return;
		}
		$(".radio[name='"+name+"'].active").removeClass("active");
		$(this).addClass("active");
	});
	//按钮样式
	var browser = getBrowserInfo() ;
	var verinfo = (browser+"").replace(/[^0-9.]/ig,"");
	if(browser.indexOf("msie") != -1 && Number(verinfo)<9){
		errorMsg("此系统暂时不支持该浏览器")
	}
});
//获取浏览器及版本
function getBrowserInfo(){
	var agent = navigator.userAgent.toLowerCase() ;

	var regStr_ie = /msie [\d.]+;/gi;
	var regStr_ff = /firefox\/[\d.]+/gi;
	var regStr_chrome = /chrome\/[\d.]+/gi;
	var regStr_saf = /safari\/[\d.]+/gi;
//IE
	if(agent.indexOf("msie") > 0){
		return agent.match(regStr_ie)[0];
	}
//firefox
	if(agent.indexOf("firefox") > 0){
		return agent.match(regStr_ff)[0];
	}
//Safari
	if(agent.indexOf("safari") > 0 && agent.indexOf("chrome") < 0){
		return agent.match(regStr_saf)[0];
	}
//Chrome
	if(agent.indexOf("chrome") > 0){
		return agent.match(regStr_chrome)[0];
	}
}
//获取像素的值
function getpxValue(str){
    return Number(str.substr(0,str.indexOf("px")));
}
//成功信息
function successMsg(msg, back){
	layer.msg(msg, {
		icon: 6,
		time: 1000,
		shade: 0.01
	}, function(){
		if(back != null && typeof back === 'function'){
			back();
		}
	});
}
//错误信息
function errorMsg(msg, back){
	layer.msg(msg, {
		icon: 5,
		time: 1000,
		shade: 0.1
	}, function(){
		if(back != null && typeof back === 'function'){
			back();
		}
	});
}
//自动处理成功/失败消息
function autoMsg(msg, success, error){
	if(msg != null && msg.length > 0){
		if(msg.indexOf("成功") != -1){
			successMsg(msg, success);
		}else{
			errorMsg(msg, error);
		}
	}
}
//刷新main容器
function redirect(url){
	if(url.length > 0){
		if(url.indexOf("?") != -1){
			$("#main").attr("src",url+"&r="+Math.random());
		}else{
			$("#main").attr("src",url+"?r="+Math.random());
		}
	}
}
//获取请求字段
function getQueryString(name){
     var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
     var r = window.location.search.substr(1).match(reg);
     if(r!=null)return  unescape(r[2]); return null;
}
//弹窗
function laywindow(title,url,width,height,callback){
	layui.layer.open({
		type: 2,
		title: title,
		shadeClose: true,
		content: url,
		area: [width, height],
		/*offset: '50px',*/
		moveOut: true,
		cancel: function(index, layero){ 
		   if(callback != null && typeof callback === 'function'){
			   callback(index, layero);
		   }
		} 
	});
}
//关闭弹窗
function laywindowclose(){
	var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
	parent.layer.close(index); //再执行关闭
	//layui.layer.closeAll('iframe');
}
//显示loading
function showloading(){
	$loading = $('<div class="loading"><img src="/image/bgms/loading.gif" /></div>');
	$("body").append($loading);
}
//取消loading
function hideloading(){
	$(".loading").remove();
}
//格式化日期对象
function formatDate(date){
	return (Number(date['year'])+1900)+"-"+(Number(date['month'])+1)+"-"+date['date'];
}
//获取表单数据
function formdata(obj){
	var params = {};
	$(obj).find("*").each(function(){
		if($(this).is("input") || $(this).is("select") || $(this).is("textarea")) {
			if(($(this).is("input[type='radio']") && $(this).is(":checked")) || !$(this).is("input[type='radio']")){
				params[$(this).attr("name")] = $(this).val();
			}
		}
	});
	return params;
}
//初始化layui表格
function initlaytable(option){
	var tableIns = layui.table.render({
		elem: '#'+option.id,
		height: 'full',
		url: option.url, //数据接口
		method: 'post',
		where: {},
		page: true, //开启分页
		id: option.id,
		done: function(res, curr, count){
			
		},
		request: {
			pageName: option.entity+'.pagenum', //页码的参数名称，默认：page
			limitName: option.entity+'.pagesize' //每页数据量的参数名，默认：limit
		},
		cols:option.cols
	});
	return tableIns;
}
function incomplete(){
	errorMsg("功能尚未开放，请联系右侧flag杯微博");
}
//获取json对象个数
function getJsonLength(jsonData){
	var jsonLength = 0;
	for(var item in jsonData){
		jsonLength++;
	}
	return jsonLength;
}